/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: javaseapp - MyUtil
 * <p>Powered by webrx On 2021-08-06 09:02:55
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class MyUtil {
    public int sum(int a, int b) {
        return a + b;
    }

    /**
     * 在方法有形参中，...代表是数组参数，可以为不填写
     *
     * @param numbs int[]
     * @return int
     */
    public int sum(int... numbs) {
        int s = 0;
        for (int i : numbs) {
            s += i;
        }
        return s;
    }

    /**
     * 求最大值
     *
     * @param a int[]
     * @return int
     */
    public static int max(int... a) {
        int max = 0;
        //a.length 返回参数的个数，本质就是数组元素的个数
        if (a.length > 0) {
            max = a[0];
            for (int i = 1; i < a.length; i++) {
                if (max < a[i]) {
                    max = a[i];
                }
            }
        }
        return max;
    }

    public static int min(int... a) {
        int min = 0;
        if (a.length > 0) {
            min = a[0];
            for (int i = 1; i < a.length; i++) {
                if (min > a[i]) {
                    min = a[i];
                }

            }
        }
        return min;
    }
}
